package camera

import (
	"net/url"
	"onvif_server/internal/model/field"
	"onvif_server/pkg/db"
)

type CreateReq struct {
	DeviceId string `json:"device_id" binding:"omitempty"`
	//DeviceId string `json:"device_id"  binding:"required,max=100"`
	Alias    string `json:"alias"  binding:"required,max=100"`
	Build    string `json:"build" binding:"required,max=100"`
	Storey   string `json:"storey" binding:"required,max=100"`
	Location string `json:"location" binding:"required,max=100"`
	Addx     string `json:"addx" binding:"omitempty"`
	//Online   int    `json:"online" `
	Username string `json:"username" binding:"omitempty,max=100"`
	Password string `json:"password" binding:"omitempty,max=100"`
	Record   bool   `json:"record" binding:"omitempty"`

	Point *field.Point `json:"point"  binding:"omitempty"`

	UUID     string `json:"uuid" binding:"required,max=100"`
	RtspUri  string `json:"rtsp_uri" binding:"required,max=100"`
	RtspUri1 string `json:"rtsp_uri1" binding:"required,max=100"`
	RtspUri2 string `json:"rtsp_uri2" binding:"omitempty"`
}

type ListReq struct {
	Keyword string `json:"keyword" query:"keyword" form:"keyword" binding:"omitempty"`
	db.Paginator
}

type DeleteReq struct {
	IDs []int `json:"ids" query:"ids" form:"ids"  binding:"required,min=1,unique,dive,gt=0"`
}

type GetM3u8Req struct {
	DeviceId string `json:"device_id" query:"device_id" form:"device_id" binding:"required"`
	Time     int64  `json:"time" query:"time" form:"time" binding:"required"`
}

type GetMp4ByImgReq struct {
	Img string `json:"img" query:"img" form:"img" binding:"required"`
}

type GetHistoryReq struct {
	DeviceId string `json:"device_id" query:"device_id" form:"device_id" binding:"required"`
}
type VideoSearchReq struct {
	DeviceId  string `json:"device_id" query:"device_id" form:"device_id" binding:"required"`
	StartTime string `json:"start_time" query:"start_time" form:"start_time"  binding:"required"` // YYYY-mm-dd HH:MM:SS
	EndTime   string `json:"end_time" query:"end_time" form:"end_time"  binding:"required"`       // YYYY-mm-dd HH:MM:SS
}

type GetSnapUrlReq struct {
	DeviceId string `json:"device_id" query:"device_id" form:"device_id" binding:"omitempty"`
	Addx     string `json:"addx" query:"addx" form:"addx" binding:"omitempty"`
	Username string `json:"username" query:"username" form:"username" binding:"omitempty"`
	Password string `json:"password" query:"password" form:"password" binding:"omitempty"`
}

type GetHistoryRes struct {
	Data        interface{} `json:"data"`
	FileList    interface{} `json:"file_list"`
	FileListNew interface{} `json:"file_list_new"`
}

type IdOrDeviceIdReq struct {
	Id       int    `json:"id" query:"id" form:"id" binding:"required_without=DeviceId"`
	DeviceId string `json:"device_id" query:"device_id" form:"device_id" binding:"required_without=Id"`
}

type UpdateReq struct {
	DeviceId string `json:"device_id" binding:"required"`
	//DeviceId string `json:"device_id"  binding:"required,max=100"`
	Alias    string `json:"alias"  binding:"required,max=100"`
	Build    string `json:"build" binding:"required,max=100"`
	Storey   string `json:"storey" binding:"required,max=100"`
	Location string `json:"location" binding:"required,max=100"`
	Addx     string `json:"addx" binding:"omitempty"`
	//Online   int    `json:"online" `
	Username string       `json:"username" binding:"required,max=100"`
	Password string       `json:"password" binding:"required,max=100"`
	Record   bool         `json:"record" binding:"omitempty"`
	Point    *field.Point `json:"point"  binding:"omitempty"`

	UUID     string `json:"uuid" binding:"required,max=100"`
	RtspUri  string `json:"rtsp_uri" binding:"required,max=100"`
	RtspUri1 string `json:"rtsp_uri1" binding:"required,max=100"`
	RtspUri2 string `json:"rtsp_uri2" binding:"omitempty"`
}

func (r *UpdateReq) Fields() []string {
	return []string{"alias", "build", "storey", "location", "addx", "username", "password", "record", "point", "uuid", "rtsp_uri", "rtsp_uri1", "rtsp_uri2"}
}

type DiscoveryCameraListRes struct {
	Name   string     `json:"name"`
	XAddrs []*url.URL `json:"-"`
	Addx   string     `json:"addx"`
	Uuid   string     `json:"uuid"`
	Exists bool       `json:"exists"`
	Id     int        `json:"id"`
}
